package thread;

public class MyRunnable implements Runnable{
    @Override
    public void run() {
        int i = 1;
        while (i-- > 0){
            System.out.println(Thread.currentThread().getName() + "正在执行");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = new MyRunnable();
        Thread thread = new Thread(runnable);
        thread.start();
        while (true){
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }

    public static void main1(String[] args) throws InterruptedException {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    System.out.println("hello runnable");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        });
        t.start();
        while (true){
            System.out.println("hello thread");
            Thread.sleep(1000);
        }
    }

//    public static void main3(String[] args) {
//        Thread t = new Thread(()->{
//            while (true){
//                System.out.println("hello thread");
//                try {
//                    Thread.sleep(1000);
//                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
//                }
//            }
//        });
//        t.setDaemon(true);
//        t.start();
//        while (true){
//            System.out.println("hello thread1");
//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//        }
//    }
}
